package com.csproj.system.repository;



import com.csproj.system.domain.Dictionary;
import com.csproj.system.repository.custom.DictionaryRepositoryCustom;
import org.springframework.data.jpa.repository.*;

import java.util.List;


/**
 * Spring Data JPA repository for the Dictionary entity.
 */
public interface DictionaryRepository extends JpaRepository<Dictionary,String>, DictionaryRepositoryCustom {

	/**
	 * 查询所有未删除数据字典信息
	 */
	@Query(" from Dictionary dt where dt.deletedFlag = 0 ")
	List<Dictionary> findAll();
	
	/**
	 * 删除数据字典
	 * @param id
	 */
	@Modifying
	@Query( " update Dictionary set deletedFlag = 1 where id = ?1 ")
	void delete(String id);
	
	/**
	 * 根据字典类型查询出所有字典标签列表
	 * @param type
	 */
	@Query(" from Dictionary dt where dt.deletedFlag = 0 and dt.dictionaryType = ?1 ")
	List<Dictionary> getDictListByType(String type);

	/**
	 * 根据字典类型查询出所有字典标签列表
	 * @param type
	 */
	@Query(" from Dictionary dt where dt.deletedFlag = 0 and dt.dictionaryType = ?1 and dt.itemKey = ?2")
	Dictionary getDictListByTypeAndItemKey(String type, String itemKey);

	Dictionary findFirstByDictionaryName(String dictionaryName);
}
